import * as actionTypes from './actionTypes';
import { localStorageTool } from '../../../config/utils';

const defaultState = {
    searchStatus: 0,
    searchText: '',
    hotsData: ['成都', '彩虹', '答案', '可乐', '借我', '戒烟', '等你下课', '斑马斑马'],
	historyData: JSON.parse(localStorageTool('read', 'scoreInfo')) || [],
	scoreData: []
};

export default (state = defaultState, action) => {
	const newState = JSON.parse(JSON.stringify(state))
	switch(action.type) {
		case actionTypes.Operate_Change_Text:
			newState.searchText = action.data
			return newState;
		case actionTypes.Operate_Delete_Text:
			newState.searchStatus = 0
			newState.searchText = ''
			return newState;
		case actionTypes.Operate_Confirm_Text:
			newState.searchStatus = 2
			newState.scoreData = action.data
			if (JSON.stringify(newState.scoreData) === '[]') {
				// 搜索 转态  0 未开始   1 加载中  2  加载完成   3 没数据
				newState.searchStatus = 3
			}
			newState.historyData = JSON.parse(localStorageTool('read', 'scoreInfo')) || []
			return newState;
		case actionTypes.Operate_Select_Label:
			newState.searchText = action.data
			return newState;
		case actionTypes.Operate_Empty_History:
			console.log('1212312132132')
			localStorageTool('clear', 'scoreInfo')
			newState.historyData = JSON.parse(localStorageTool('read', 'scoreInfo')) || []
			return newState;
		default:
			return state;
	}
}